package main

import (
	"fmt"
	"sync"
)

//因为 两个协程都被卡住，主协程的wait会一直执行不了，也被卡住，所以报死锁的错
func main() {
	var chan1 = make(chan int)
	var rwm sync.RWMutex
	var wg sync.WaitGroup
	wg.Add(2)
	//read
	go func() {
		rwm.RLock()
		<-chan1
		rwm.RUnlock()
		wg.Done()
	}()
	//write
	go func() {
		rwm.Lock()
		chan1 <- 1
		rwm.Unlock()
		wg.Done()
	}()
	wg.Wait()
	fmt.Println("main over")
}
